﻿using System;
using System.Xml.Serialization;

namespace KBEngine.Setting.Internal
{
    [Serializable]
    public class BaseApp
    {
        /// <summary>
        /// 脚本入口模块， 相当于main函数
        /// </summary>
        public string entryScriptFile = "kbemain";
        /// <summary>
        /// 指定接口地址，可配置网卡名、MAC、IP
        /// </summary>
        public string internalInterface = string.Empty;
        public string externalInterface = string.Empty;
        /// <summary>
        /// 强制指定外部IP地址或者域名，在某些网络环境下，可能会使用端口映射的方式来访问局域网内部的KBE服务器，那么KBE在当前
        /// 的机器上获得的外部地址是局域网地址，此时某些功能将会不正常。例如：账号激活邮件中给出的回调地址, 登录baseapp。
        ///	注意：服务端并不会检查这个地址的可用性，因为无法检查。
        /// </summary>
        public string externalAddress = string.Empty;

        public int externalTcpPorts_min = 20015;
        public int externalTcpPorts_max = 20019;
        public int externalUdpPorts_min = 20005;
        public int externalUdpPorts_max = 20009;

        /// <summary>
        /// 自动存档的时间周期(秒)
        /// </summary>
        public float archivePeriod = 300;

        /// <summary>
        /// 自动备份的时间(秒)
        /// </summary>
        public float backupPeriod = 300;

        /// <summary>
        /// 是否备份未定义的属性(bool)
        /// </summary>
        public int backUpUndefinedProperties = 0;

        /// <summary>
        /// 负载平衡滤波器指标值
        /// </summary>
        public float loadSmoothingBias = 0.01f;

        /// <summary>
        /// 资源下载带宽限制
        /// </summary>
        public DownloadStreaming downloadStreaming = new DownloadStreaming();

        /// <summary>
        /// entityID分配器，进入溢出范围则请求获取新的ID资源
        /// </summary>
        public BaseApp_Ids ids = new BaseApp_Ids();

        /// <summary>
        /// 当灾难发生后，baseapp进行灾难恢复时，每次恢复entity的数量
        /// </summary>
        public ushort entityRestoreSize = 32;
        public Profiles profiles = new Profiles();

        /// <summary>
        /// listen监听队列最大值
        /// </summary>
        [XmlElement("SOMAXCONN")]
        public uint somaxconn = 511;

        public TelnetService telnet_service = new TelnetService();

        /// <summary>
        /// 关闭服务端_每秒销毁base的数量
        /// </summary>
        public BaseApp_Shutdown shutdown = new BaseApp_Shutdown();

        /// <summary>
        /// 缓冲区设置
        /// </summary>
        public Respool respool = new Respool();

        [Serializable]
        public class DownloadStreaming
        {
            public uint bitsPerSecondTotal = 1000000;
            public uint bitsPerSecondPerClient = 1000000;
        }

        [Serializable]
        public class BaseApp_Ids
        {
            public int criticallyLowSize = 1000;
        }
        [Serializable]
        public class BaseApp_Shutdown
        {
            public uint perSecsDestroyEntitySize = 100;
        }

        [Serializable]
        public class Respool
        {
            /// <summary>
            /// 缓冲区大小也等于资源大小， 在这个KB大小范围以内的资源才可以进入资源池
            /// </summary>
            public uint buffer_size = 1024;

            /// <summary>
            /// 资源池中的资源超过这个时间未被访问则销毁(秒)
            /// </summary>
            public uint timeout = 600;

            /// <summary>
            /// 资源池检查tick(秒)
            /// </summary>
            public uint checktick = 60;
        }
    }
}
